<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class WdminPage extends Controller {

    const TPL = './views/wdminpage/';

    public function __construct($ControllerName, $Action, $QueryString) {
        parent::__construct($ControllerName, $Action, $QueryString);
        $this->loadModel('Db');
    }

    /**
     * 报表首页
     */
    public function home() {
        $this->show();
    }

    /**
     * 订单首页
     */
    public function orders() {
        $this->show(self::TPL . 'orders/exp_orders.tpl');
    }

    /**
     * 所有订单
     */
    public function all_orders() {
        $this->show(self::TPL . 'orders/all_orders.tpl');
    }

    /**
     * 所有产品
     */
    public function list_products() {
        $this->show(self::TPL . 'products/list_products.tpl');
    }

    /**
     * 编辑商品信息
     * @param type $Query
     */
    public function iframe_alter_product($Query) {
        $this->loadModel('Product');
        $mod = $Query->mod;
        $serials = $this->Product->getSerials();
        if ($mod == 'edit') {
            $pid = $this->pGet('id');
            $productInfo = $this->Product->getProductInfo($pid);
            $this->Smarty->assign('ed', true);
            $this->Smarty->assign('pd', $productInfo);
            $this->Smarty->assign('cat', $productInfo['product_cat']);
        } else {
            $cat = $Query->catid;
            $this->Smarty->assign('ed', false);
            $this->Smarty->assign('cat', $cat);
        }
        $this->Smarty->assign('serials', $serials);
        $this->Smarty->assign('mod', $mod);
        $this->show(self::TPL . 'products/iframe_alter_product.tpl');
    }

    /**
     * 
     * @param type $Query
     */
    public function iframe_list_product($Query) {
        $cat = $Query->cat ? intval($Query->cat) : 0;
        $page = $Query->page ? intval($Query->page) : 0;
        $part = isset($Query->part);
        $this->cacheId = $cat . $page . $part;
        if (!$this->isCached()) {
            $listLim = 50;
            $lim = $Query->page * $listLim . "," . $listLim;
            $this->loadModel('Product');
            $productList = $this->Product->getProductList('product_id DESC', $lim, $cat);
            $this->Smarty->assign('cat', $cat);
            $this->Smarty->assign('page', $page);
            $this->Smarty->assign('list', $productList);
            $this->Smarty->assign('listCount', count($productList));
        }
        if (!$part) {
            $this->show(self::TPL . 'products/iframe_list_products.tpl');
        } else {
            $this->show(self::TPL . 'products/iframe_list_products_jsarray.tpl');
        }
    }

    public function alter_products() {
        $this->show(self::TPL . 'products/alter_products.tpl');
    }

    public function alter_products_category() {
        $this->show(self::TPL . 'products/alter_products_category.tpl');
    }

    public function alter_category($Query) {
        $id = intval($Query->id);
        // ch
        if (is_numeric($id)) {
            $this->loadModel('Product');
            $cati = $this->Product->getCatInfo($id);
            $this->cacheId = hash('md4', $id . $cati['cat_name']);
            $this->Smarty->assign('id', $id);
            $this->Smarty->assign('cat', $cati);
            $this->show(self::TPL . 'products/alter_category.tpl');
        }
    }

    public function gmess() {
        $this->show(self::TPL . 'gmess/send.tpl');
    }

    public function list_customers() {
        $this->show(self::TPL . 'customers/list_customers.tpl');
    }

}
